#coding:utf-8

'''
email: chenyan@feling.net

x的n次方
'''

def power_x(x,n):
    '''
    >>> power_x(2,8) == 2**8
    True
    >>> power_x(3,0)
    1
    >>> power_x(3,1)
    3
    >>> power_x(2,9) == 2**9
    True
    >>> power_x(3,-1)
    -1
    >>> power_x(-3,3) == (-3)**3
    True
    '''
    if n<0: 
        return -1
    if n==0:
        return 1
    if n%2==0:
        return power_x(x,n//2)*power_x(x,n//2)
    if n%2==1:
        return power_x(x,(n-1)//2)*power_x(x,(n-1)//2)*x

if __name__=='__main__':
    import doctest
    doctest.testmod()
